<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>流程管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${ctx }/resources/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${ctx }/resources/css/public.css" media="all" />
</head>
<body class="childrenBody">

<!--  搜索 查询   -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
  <legend>查询条件</legend>
</fieldset>
<form class="layui-form" id="searchFrm">
<div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">部署名称</label>
      <div class="layui-input-inline">
        <input type="text" name="deploymentName" id="deploymentName" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    	<a href="javascript:void(0)" class="search_btn layui-btn">查询</a>
    	<button type="reset" class="layui-btn layui-btn-warm" >重置</button>
 </div>
</form>

<!-- 数据表格 -->
	<table id="processDeploymentList" lay-filter="processDeploymentList"></table>
	<br>
	<table id="processDefList" lay-filter="processDefList"></table>
	<!--表格工具条  批量删除-->
	<script type="text/html" id="tableToolBar">
		<a class="layui-btn layui-btn" lay-event="add">添加部署</a>
	</script>
	
	<!-- 操作 -->
	<!--表格数据 工具条-->
	<script type="text/html" id="processDeploymentListBar">
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
		<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="viewProcessImage">查看流程图</a>
	</script>

<script type="text/javascript" src="${ctx }/resources/layui/layui.js"></script>
<script type="text/javascript">
var tableInsDeployment;
var tableInsProcessDef;

    layui.use(['form','layer','table'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            table = layui.table;

        //流程部署列表
        tableInsDeployment = table.render({
            elem: '#processDeploymentList',
            url : '${ctx}/workFlow/loadAllProcessDeployment.action',
            cellMinWidth : 95,
            toolbar: '#tableToolBar',
            page : true,
            height : "full-300",
            limit : 10,
            limits : [10,15,20,25],
            id : "processDeploymentListTable",
            cols : [[
                {type: "checkbox", fixed:"left", width:50},
                {field: 'id', title: '部署ID', width:100, align:"center"},
                {field: 'name', title: '部署名称', align:"center",width:150},
                {field: 'deploymentTime', title: '部署时间', align:'center',width:200},
                {title: '操作', width:200, templet:'#processDeploymentListBar',fixed:"right",align:"center"}
            ]]
        });
        
        //流程定义列表
        tableInsProcessDef = table.render({
            elem: '#processDefList',
            url : '${ctx}/workFlow/loadAllProcessDef.action',
            cellMinWidth : 95,
            toolbar: true,
            page : true,
            height : "full-300",
            limit : 10,
            limits : [10,15,20,25],
            defaultToolbar: ['filter'],
            id : "processDefListTable",
            cols : [[
                {type: "checkbox", fixed:"left", width:50},
                {field: 'id', title: '定义ID', width:100, align:"center"},
                {field: 'name', title: '定义名称', align:"center",width:100},
                {field: 'key', title: '定义KEY', align:"center",width:100},
                {field: 'version', title: '定义版本', align:"center",width:100},
                {field: 'deploymentId', title: '部署ID', align:"center",width:100},
                {field: 'resourceName', title: '资源名称[bpmn]', align:"center",width:200},
                {field: 'diagramResourceName', title: '资源名称[png]', align:"center",width:200},
            ]]
        });
        
        //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
        $(".search_btn").on("click",function(){
        	var params=$("#searchFrm").serialize();
        	table.reload("processDeploymentListTable",{
        	    url: '${ctx }/workFlow/loadAllProcessDeployment.action?'+params
        	});       
        	table.reload("processDefListTable",{
        	    url: '${ctx }/workFlow/loadAllProcessDef.action?'+params
        	});       
        });
        
        //监听头工具栏事件
        table.on('toolbar(processDeploymentList)', function(obj){
            switch(obj.event){
            	case 'add':
            		toAddDeployment();
            		break;
            };
        });

      //准备添加，打开添加页面
      function toAddDeployment() {
		var index= layui.layer.open({
			title:'添加流程部署',
			type: 2, 
			area: ['800px','300px'],
			content: '${ctx}/workFlow/toAddDeployment.action' , //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			success : function(layero, index){
	                  setTimeout(function(){
	                      layui.layer.tips('点击此处返回流程部署列表', '.layui-layer-setwin .layui-layer-close', {
	                          tips: 3
	                      });
	                  },500)
	              }
		})
		//默认最大化窗口
	          //layui.layer.full(index);
	          //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
		$(window).on("resize",function(){
            layui.layer.full(index);
        })
	}


        //列表操作
        table.on('tool(processDeploymentList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;
            if(layEvent === 'del'){ //删除
            	layer.confirm('确定删除此流程？',{icon:3, title:'提示信息'},function(index){
                    $.post("${ctx}/workFlow/deleteDeployment.action?deploymentId="+data.id,function(data){
                    	layer.msg(data.msg);
                    	//刷新table
                        tableInsDeployment.reload();
                        tableInsProcessDef.reload();
                        layer.close(index);
                    }),
                  	//刷新table
                    tableInsDeployment.reload();
                    tableInsProcessDef.reload();
                })
            }else if(layEvent === 'viewProcessImage'){
            	viewProcessImage(data);
            }   
        });
        
      //打开流程部署分配层
        function viewProcessImage(data) {
        	var index= layui.layer.open({
    			title:'查看【'+data.name+'】流程图',
    			type: 2, 
    			area: ['800px','600px'],
    			content: '${ctx}/workFlow/toViewProcessImage.action?deploymentId='+data.id , //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    			success : function(layero, index){
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回流程部署列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }
    		})
    		//默认最大化窗口
            //layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
    		$(window).on("resize",function(){
                layui.layer.full(index);
            })
    	}

    });
    
  

</script>
</body>
</html>